package com.sayice.robotconflict.game.msg;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;

/**
 * 游戏服务端与客户端的通信消息
 *
 * @author shubing
 */
@Getter
@Setter
@ToString
public class Message implements Serializable {
    private static final long serialVersionUID = 1L;
    
    /**
     * 消息类型
     */
    private String type;
    
    /**
     * 操作
     */
    private String action;
    
    /**
     * 数据
     */
    private Object data;
    
    public Message() {
    }
    
    public Message(String type, String action, Object data) {
        this.type = type;
        this.action = action;
        this.data = data;
    }
    
    /**
     * 转换为 JSON 字符串
     */
    public String toJson() {
        return JSON.toJSONString(this, JSONWriter.Feature.WriteEnumsUsingName);
    }
}
